#include "windowslnkthumbnail.h"
#include <QString>
#include <QImage>
#include <QTemporaryFile>
#include <QProcess>

extern "C" {
 KDE_EXPORT ThumbCreator *new_creator() {
   return new WindowsLnkCreator;
 }
}

bool WindowsLnkCreator::create(const QString& path, int width, int height, QImage& img)
{
  QTemporaryFile pngTempFile;
  QImage iconFile;
  
  if ( ! pngTempFile.open() )
    return false;
  
  // convert lnk to png(path, pngTempFile.fileName, width, height);
  QProcess winemenuBuilder;
  winemenuBuilder.start("wine", QStringList() << "winemenubuilder" << "-t" << path << pngTempFile.fileName());
  winemenuBuilder.waitForFinished();
  
  if ( winemenuBuilder.exitCode() != 0 ) 
    return false;
  
  
  if ( ! iconFile.load(pngTempFile.fileName()) )
    return false;
  
  img = iconFile.scaled(width, height, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  if ( img.isNull() )
    return false; 
  
  return true;
  // actually create the thumbail! 
}

